﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Data_Access_Layer;
namespace Business_Layer
{
	public class AccountController
	{
		public List<Account> GetAll()
		{
			return Account.Objects.Where(x => x.Deleted == false).ToList();
		}
		public bool Delete(Account emp)
		{
			Account.Objects.Update(emp);
			return true;
		}
		public string _err = "";

		public bool Insert_Update(Account acc)
		{
			try
			{
				if (acc.Id > 0)
				{
					Account.Objects.Update(acc);
					return true;
				}
				else
				{
					Account.Objects.Insert(acc);
					return true;
				}
			}
			catch (Exception ex)
			{
				_err = ex.Message;
				return false;
			}
		}

		public Account FindById(int id)
		{
			return Account.Objects.FirstOrDefault(x => x.Id == id && x.Deleted == false);
		}
		public List<Account> FindByUsername(string username)
		{
			return Account.Objects.Where(x => x.Username.IndexOf(username) != -1 && x.Deleted == false).ToList();
		}
		public Account FindByName_EmpId(int empid)
		{
			return Account.Objects.FirstOrDefault(x => x.EmpId == empid && x.Deleted == false);
		}
	}
}
